<!-- 心理专家确定心理量表（后台）
1.	系统根据该心理专家id列表展示所负责的普测业务基本信息（学校名称、学校负责人、普测时间、人数、业务进度）
2.	选定已提交状态的普测业务
3.	系统显示普测需求
4.	选择心理测评指标、心理问卷、评分规则及分类规则
5.	设置答卷时长
6.	点击“提交”按钮
7.	系统保存该普测业务的心理量表信息，该普测业务的状态更新为设置完成
8.	显示保存成功提示框
9.	系统返回展示该业务信息 
-->
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="学校名称" prop="schName">
        <el-input
          v-model="queryParams.schName"
          placeholder="请输入学校名称"
          clearable
          style="width: 200px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="普测时间" prop="testTime">
        <el-date-picker
          v-model="value1"
          clearable
          type="date"
          placeholder="请选择进行普测的时间"
          :size="size"
          style="width: 200px"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row>
      <el-col :span="1.5">
        <el-text size="large" type="primary">当前普测业务列表</el-text>
      </el-col>
      <!-- 隐藏搜索和刷新按钮 -->
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="schList">
      <!-- 学校名称 -->
      <el-table-column
        prop="schName"
        label="学校名称"
        width="150px"
      ></el-table-column>
      <!-- 学校领导 -->
      <el-table-column
        prop="schLeader"
        label="学校负责人"
        width="120px"
      ></el-table-column>
      <!-- 测试时间 -->
      <el-table-column label="测试时间" prop="testDate">
        <template #default="scope">
          <span>{{ parseTime(scope.row.testDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="testNum"
        label="测试人数"
        width="120px"
      ></el-table-column>
      <el-table-column prop="testProgress" label="业务进度"></el-table-column>
      <el-table-column label="操作" align="center" width="330px">
        <template #default="scope">
          <el-button
            link
            type="primary"
            icon="Pointer"
            @click="handleUpdate(scope.row)"
            >查看普测需求</el-button
          >
          <el-button
            link
            type="primary"
            icon="Edit"
            @click="handleAdd(scope.row)"
            >编辑业务信息</el-button
          >
          <el-button
            v-if="scope.row.parentId != 0"
            link
            type="primary"
            icon="Delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 添加或修改学校对话框 -->
    <el-dialog :title="title" v-model="open" width="600px">
      <el-form ref="schRef" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="测评指标" prop="testStandard">
              <el-input
                v-model="form.testStandard"
                placeholder="请选择心理测评指标"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="心理问卷" prop="testTable">
              <el-input
                v-model="form.testTable"
                placeholder="请分配合适的心理问卷"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="评分规则" prop="scoreRules">
              <el-input
                v-model="form.scoreRules"
                placeholder="请选择评分规则"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="分类规则" prop="classifyRules">
              <el-input
                v-model="form.classifyRules"
                placeholder="请选择分类规则"
              />
            </el-form-item>
          </el-col>
          <el-col :span="14">
            <el-form-item label="测试时间" prop="testTime">
              <el-input-number
                v-model="form.testTime"
                controls-position="right"
                placeholder="单位(min)"
                :min="0"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="sch">
const schList = [
  {
    schName: '某某某',
    schLeader: '张三',
    testDate: '2024-07-25',
    testNum: 20,
    testProgress: '待处理',
    testDemand: '找出阳光的学生',
    testStandard: '',
    testTable: '',
    scoreRules: '',
    classifyRules: '',
    testTime: '',
  },
  {
    schName: '某某某',
    schLeader: '张三',
    testDate: '2024-07-25',
    testNum: 20,
    testProgress: '待处理',
    testDemand: '找出阳光的学生',
    testStandard: '',
    testTable: '',
    scoreRules: '',
    classifyRules: '',
    testTime: '',
  },
  {
    schName: '某某某',
    schLeader: '张三',
    testDate: '2024-07-25',
    testNum: 20,
    testProgress: '待处理',
    testDemand: '找出阳光的学生',
    testStandard: '',
    testTable: '',
    scoreRules: '',
    classifyRules: '',
    testTime: '',
  },
  {
    schName: '某某某',
    schLeader: '张三',
    testDate: '2024-07-25',
    testNum: 20,
    testProgress: '待处理',
    testDemand: '找出阳光的学生',
    testStandard: '',
    testTable: '',
    scoreRules: '',
    classifyRules: '',
    testTime: '',
  },
]
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const title = ref('')

const data = reactive({
  form: {},
  queryParams: {
    testStandard: undefined,
    testTable: undefined,
  },
  rules: {
    testStandard: [
      { required: true, message: '测评指标不能为空', trigger: 'blur' },
    ],
    testTable: [
      { required: true, message: '心理量表不能为空', trigger: 'blur' },
    ],
    scoreRules: [
      { required: true, message: '评分标准不能为空', trigger: 'blur' },
    ],
    classifyRules: [
      { required: true, message: '分类标准不能为空', trigger: 'blur' },
    ],
    testTime: [
      { required: true, message: '测试时间不能为空', trigger: 'blur' },
    ],
  },
})

const { queryParams, form, rules } = toRefs(data)

/** 查询学校列表 */
function getList() {
  loading.value = false
  //  listsch(queryParams.value).then(response => {
  //    schList.value = proxy.handleTree(response.data, "schId");
  //    loading.value = false;
  //  });
}

/** 取消按钮 */
function cancel() {
  open.value = false
  //  reset();
}

/** 表单重置 */
function reset() {
  //  form.value = {
  //    schId: undefined,
  //    parentId: undefined,
  //    schName: undefined,
  //    testNum: 0,
  //    leader: undefined,
  //    phone: undefined,
  //    email: undefined,
  //    testTime: "0"
  //  };
  //  proxy.resetForm("schRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  //  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  //  proxy.resetForm("queryRef");
  //  handleQuery();
}

/** 新增按钮操作 */
function handleAdd(row) {
  //  reset();
  //  listsch().then(response => {
  //    schOptions.value = proxy.handleTree(response.data, "schId");
  //  });
  //  if (row != undefined) {
  //    form.value.parentId = row.schId;
  //  }
  open.value = true
  title.value = '添加学校'
}

/** 修改按钮操作 */
function handleUpdate(row) {
  //  reset();
  //  listschExcludeChild(row.schId).then(response => {
  //    schOptions.value = proxy.handleTree(response.data, "schId");
  //  });
  //  getsch(row.schId).then(response => {
  //    form.value = response.data;
  //    open.value = true;
  //    title.value = "修改学校";
  //  });
}

/** 提交按钮 */
function submitForm() {
  alert('添加成功')
  //  proxy.$refs["schRef"].validate(valid => {
  //    if (valid) {
  //      if (form.value.schId != undefined) {
  //        updatesch(form.value).then(response => {
  //          proxy.$modal.msgSuccess("修改成功");
  //          open.value = false;
  //          getList();
  //        });
  //      } else {
  //        addsch(form.value).then(response => {
  //          proxy.$modal.msgSuccess("新增成功");
  //          open.value = false;
  //          getList();
  //        });
  //      }
  //    }
  //  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  //  proxy.$modal.confirm('是否确认删除名称为"' + row.schName + '"的数据项?').then(function() {
  //    return delsch(row.schId);
  //  }).then(() => {
  //    getList();
  //    proxy.$modal.msgSuccess("删除成功");
  //  }).catch(() => {});
}

getList()
</script>
